﻿using NFine.Application.BusinessManage;
using NFine.Application.SystemManage;
using NFine.Code;
using NFine.Domain.Entity.BusinessManage;
using System.Web.Mvc;

namespace NFine.Web.Areas.BusinessManage.Controllers
{
    public class D_GroupMemberController : ControllerBase
    {
        //
        // GET: /BusinessManage/D_GroupMember/

        private D_GroupMemberApp membersApp = new D_GroupMemberApp();
        private UserApp userApp = new UserApp();

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetGridJson(Pagination pagination, string keyword)
        {
            var data = new
            {
                //rows = membersApp.GetList(pagination, keyword),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetFormJson(string keyValue)
        {
            var data = membersApp.GetForm(keyValue);
            return Content(data.ToJson());
        }
        [HttpPost]
        [HandlerAjaxOnly]
        [ValidateAntiForgeryToken]
        public ActionResult SubmitForm(D_GoodsEntity areaEntity, string keyValue)
        {
            //membersApp.SubmitForm(areaEntity, keyValue);
            return Success("操作成功。");
        }
        [HttpPost]
        [HandlerAjaxOnly]
        [HandlerAuthorize]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteForm(string keyValue)
        {
            membersApp.DeleteForm(keyValue);
            return Success("删除成功。");
        }

        public ActionResult GroupMembers(string id = "")
        {
            string userid = "";
            if (string.IsNullOrEmpty(id))
            {
                var provier = OperatorProvider.Provider.GetCurrent();
                if (provier.IsMember)
                {
                    id = provier.UserCode;
                    userid = provier.UserId;
                }
                else
                {
                    var fu = userApp.FindEntityByFunc(u => string.IsNullOrEmpty(u.ReferenceID) && !u.F_IsAdministrator.Value);
                    id = fu.F_Account;
                }
            }
            var lst = membersApp.GetGroupMembers(id);
            if (lst != null)
            {
                ViewBag.CurrentUserID = userid;
                return View(lst);
            }
            else
            {
                return new ContentResult() { Content = "该用户不存在" };
            }
        }

    }
}
